home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / convert / headers.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-02  |  3.7 KB  |  139 lines

  1. /*
  2. %    HEADERS . C
  3. %
  4. % Display image header for HIPS, FIST, GIF, PNM, RLE, SUN-RASter, and TIFF
  5. %
  6. %    Copyright (c)    1991    Jin Guojun
  7. %
  8. %    Permission to use, copy, modify, and distribute this software and
  9. % its documentation for any purpose is hereby granted, provided that the above
  10. % copyright notice appear in all copies and that both that copyright notice
  11. % and this permission notice appear in supporting documentation.
  12. %
  13. % compile:    cc -O -o headers headers.c -lscs5 -lccs -lhips -lrle -ltiff ...
  14. %
  15. % AUTHOR:    Jin Guojun - LBL    12/10/91
  16. */
  17.  
  18. #include <string.h>
  19. #include "header.def"
  20. #include "imagedef.h"
  21. #include <math.h>
  22.  
  23. #ifndef    SBUF_LEN
  24. #define    SBUF_LEN    256
  25. #endif
  26.  
  27. U_IMAGE    uimg;
  28. char    usage[]="headers image_files ... ",
  29.     *color_or_grayscale(),    /* returns    color format */
  30.     *format_string();    /* returns    format desciption */
  31.  
  32.  
  33. main(argc, argv)
  34. int    argc;
  35. char*    argv[];
  36. {
  37. int    f = 0;
  38.  
  39. format_init(&uimg, IMAGE_INIT_TYPE, COLOR_PS, -1, *argv, "D12-1");
  40.  
  41. if (argc==1) {    /* for single file using `<' redirction input */
  42.     f--;
  43.     io_test(fileno(in_fp), usage_n_options(usage, argc, argv[argc]));
  44. }
  45. while (++f < argc) {
  46.     if (argc != 1 && (in_fp=freopen(uimg.name=argv[f], "rb", stdin))==NULL) {
  47.     prgmerr(0, "can not open %s for input", argv[f]);
  48.     continue;
  49.     }
  50.     uimg.in_type = IMAGE_INIT_TYPE;    /* important for multi-handling    */
  51.     if ((*uimg.header_handle)(HEADER_READ, &uimg, 0, 0) < 0) {
  52.     msg("%s is not in type of HIPS, FITS, GIF, ICC, PNM, RLE, SUN, and TIFF\n",
  53.         argv[f]);
  54.     continue;
  55.     }
  56.     fprintf(out_fp, "\nNAME =>    %s\n", argv[f]);
  57.     fprintf(out_fp, "Type :    %s\n", ITypeName[uimg.in_type]);
  58.     fprintf(out_fp, "color :    %s\n", color_or_grayscale(uimg.in_color));
  59.     fprintf(out_fp, "format :    %s\n", format_string(uimg.in_form));
  60.     fprintf(out_fp, "frames :    %d\n", uimg.frames ? uimg.frames : 1);
  61.     fprintf(out_fp, "size   :    %d(w) x %d(h)\n", uimg.width, uimg.height);
  62.     fprintf(out_fp, "sub-image :    %d(w) x %d(h) <%d:%d>\n",
  63.     uimg.sub_img_w, uimg.sub_img_h, uimg.sub_img_x, uimg.sub_img_y);
  64.     fprintf(out_fp, "pixel bytes :    %d\n", uimg.pxl_in);
  65.     if (print_string(out_fp, "History", uimg.history))
  66.     free(uimg.history);
  67.     if (print_string(out_fp, "Desciption", uimg.desc))
  68.     free(uimg.desc);
  69.     uimg.history = uimg.desc = NULL;
  70. }
  71. exit(0);
  72. }
  73.  
  74. char    *color_or_grayscale(type)
  75. {
  76.     switch (type) {
  77.     case CFM_SGF:
  78.         return    "GrayScale";
  79.     case CFM_SCF:
  80.         return    "8-bit Color witch color_map";
  81.     case CFM_ILL:
  82.         return    "24-bit Color, scan line";
  83.     case CFM_ILC:
  84.         return    "24-bit Color, interleaf";
  85.     case CFM_BITMAP:
  86.         return    "Bit-Map";
  87.     case CFM_ALPHA:
  88.         return    "32-bit Color (alpha channel)";
  89.     case CFM_SEPLANE:
  90.         return    "24-bit Color, separate planes";
  91.     default:    return    "Unknown color format";
  92.     }
  93. }
  94.  
  95. char*    format_string(form)
  96. {
  97.     switch (form) {
  98.     case IFMT_VFFT3D:    return    "3D VFFT";
  99.     case IFMT_VFFT2D:    return    "2D VFFT";
  100.     case IFMT_DVFFT3D:    return    "3D Double VFFT";
  101.     case IFMT_DVFFT2D:    return    "2D Double VFFT";
  102.     case IFMT_VVFFT3D:    return    "3D VFFT in separated plane";
  103.     case IFMT_DVVFFT3D:    return    "3D Double VFFT in separated plane";
  104.     case IFMT_SCF:    return    "1 byte color";
  105.     case IFMT_SEPLANE:
  106.     case IFMT_ILC:
  107.     case IFMT_ILL:    return    "3 byte color";
  108.     case IFMT_ALPHA:    return    "4 byte color";
  109.     case IFMT_BITMAP:    return    "bitmap";
  110.     default    :    return    hformatname(form);
  111.     }
  112. }
  113.  
  114. print_string(fp, phd, s)
  115. FILE    *fp;
  116. char    *phd, *s;
  117. {
  118. char    buffer[SBUF_LEN];    /* 256 is save for most case */
  119. register int    i;
  120.     if (s) {
  121.     fprintf(fp, "%s\n", phd);
  122.     do {
  123.         for (i=0; *s && *s != '\n' && i<SBUF_LEN-1; i++)
  124.             if (*s == '|' && *(s+1) == '\\')
  125.             {    s+=2;    i--;    }
  126.             else    buffer[i] = *s++;
  127.         if (!*s)
  128.             buffer[i++] = '\n';
  129.         buffer[i]=0;
  130.         i ^= i;
  131.         while(buffer[i] == ' ')    i++;
  132.         if (strlen(buffer+i))
  133.             fprintf(fp, "%s\n", buffer+i);
  134.     } while(*++s);
  135.     return    1;
  136.     } else    fprintf(fp, "No %s\n", phd);
  137. return    0;
  138. }
  139.